let five_car = new Vue({
    el: '#five_car',
    data: {
        list: [
            {
                "category": '电子产品',
                "list": [
                    {
                        id: 1,
                        name: 'iphone7',
                        price: 6188,
                        count: 1,
                        status: 0
                    }, {
                        id: 2,
                        name: 'iphone13',
                        price: 6188,
                        count: 100,
                        status: 0
                    }, {
                        id: 3,
                        name: 'iphone12',
                        price: 6188,
                        count: 5,
                        status: 0
                    }]
            },
            {
                "category": '蔬菜',
                "list": [
                    {
                        id: 1,
                        name: 'iphone7',
                        price: 6188,
                        count: 1,
                        status: 0
                    }, {
                        id: 2,
                        name: 'iphone13',
                        price: 6188,
                        count: 100,
                        status: 0
                    }, {
                        id: 3,
                        name: 'iphone12',
                        price: 6188,
                        count: 5,
                        status: 0
                    }]
            }
            //     {
            //         id: 1,
            //         name: 'iphone7',
            //         price: 6188,
            //         count: 1,
            //         status: 0
            //     }, {
            //         id: 2,
            //         name: 'iphone13',
            //         price: 6188,
            //         count: 100,
            //         status: 0
            //     }, {
            //         id: 1,
            //         name: 'iphone12',
            //         price: 6188,
            //         count: 5,
            //         status: 0
            //     }
        ]
    },
    computed: {
        totalPrice: function () {
            let total = 0;
            for (let i = 0; i < this.list.length; i++) {
                let item = this.list[i];
                for (let j = 0; j < item.list.length; j++) {
                    if (item.list[j].status === 1) {
                        total += item.list[j].price * item.list[j].count;
                    }
                }


            }
            return total.toString().replace(/\B(?=(\d{3})+$)/g, ',')
        }
    },
    methods: {
        handleReduce: function (index, index1) {
            this.list[index].list[index1].count--
        },
        handleAdd: function (index, index1) {
            this.list[index].list[index1].count++
        },
        handleRemove: function (index, index1) {
            this.list[index].list.splice(index1, 1)
        },
        // handleSelect: function (index) {
        //     this.list[index].status = this.list[index].status === 1 ? 0 : 1
        // }
        handleSelect: function (index, index1) {
            console.log(this.list[index])
            console.log(index, index1)
            this.list[index].list[index1].status = this.list[index].list[index1].status === 1 ? 0 : 1
        }
        ,
        // handleSelectAll: function () {
        //     if (this.checkboxStatus()) {
        //         for (let i = 0; i < this.list.length; i++) {
        //             let item = this.list[i];
        //             item.status = 0
        //         }
        //     } else {
        //         for (let i = 0; i < this.list.length; i++) {
        //             let item = this.list[i];
        //             item.status = 1
        //         }
        //     }
        // },

        handleSelectAll: function () {
            if (this.checkboxStatus()) {
                for (let i = 0; i < this.list.length; i++) {
                    let item = this.list[i];
                    for (let j = 0; j < item.list.length; j++) {
                        item.list[j].status = 0
                    }
                }
            } else {
                for (let i = 0; i < this.list.length; i++) {
                    let item = this.list[i];
                    for (let j = 0; j < item.list.length; j++) {
                        item.list[j].status = 1
                    }
                }
            }
        },
        checkboxStatus: function () {
            for (let i = 0; i < this.list.length; i++) {
                let item = this.list[i];
                for (let j = 0; j < item.list.length; j++) {
                    if (item.list[j].status === 0) {
                        return false;
                    }
                }
            }
            return true;
        },
        itemCount: function (index) {
            return this.list[index].list.length + 1
        }

    }
})